package com.haoma.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.haoma.dto.LinkAuditDto;
import com.haoma.dto.LinkQueryDto;
import com.haoma.entity.Link;
import com.haoma.result.Result;
import com.haoma.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: 友链相关接口
 */
@RestController
@RequestMapping("/admin/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    /**
     * 友链分页查询
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/page/{page}/{limit}")
    public Result pageLinkList(@PathVariable Long page,
                               @PathVariable Long limit,
                               LinkQueryDto linkQueryDto) {
        IPage iPage = linkService.pageLinkList(page, limit, linkQueryDto);
        return Result.success(iPage);
    }

    /**
     * 删除友链
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public Result delLink(@PathVariable Integer id) {
        linkService.delLink(id);
        return Result.success();
    }

    /**
     * 审核友链
     *
     * @param status
     * @return
     */
    @PutMapping("/applyfor/{status}")
    public Result auditLink(@PathVariable Integer status, @RequestBody @Validated LinkAuditDto linkAuditDto) {
        linkService.auditLink(status, linkAuditDto);
        return Result.success();
    }

    /**
     * 查询待处理友链
     *
     * @return
     */
    @GetMapping("/pendinglink")
    public Result getPendingLink() {
        List<Link> linkList = linkService.getPendingLink();
        return Result.success(linkList);
    }
}
